#include "stdafx.h"

int setAdamarMatrix(int *Matrix)
{
	Matrix[0] =		1;
	Matrix[1] =		1;
	Matrix[2] =		1;
	Matrix[3] =		1;
	Matrix[4] =		1;
	Matrix[5] =		1;
	Matrix[6] =		-1;
	Matrix[7] =		-1;
	Matrix[8] =		1;
	Matrix[9] =		-1;
	Matrix[10]=		-1;
	Matrix[11]=		1;
	Matrix[12]=		1;
	Matrix[13]=		-1;
	Matrix[14]=		1;
	Matrix[15]=		-1;
	return 1;
}

int * setSimpleQMatrix(int Size)
{
	int *Matrix = new int[Size * Size];
	for (int i = 0; i < Size * Size; i++)
		Matrix[i] = 7;
	return Matrix;
}

int *setQMatrix(int Size)
{
	int *M;
	if (Size > 8) M = setSimpleQMatrix(Size);
	if (Size == 4)
	{
		M = new int[16];
		int _M[] = {
					7,	16,	22,	24,
					16,	22,	24,	28,
					18,	22,	27,	33,
					22,	24,	32,	47
					};
		for (int i = 0; i < 16;i++)
		{
			M[i] = _M[i];
		}
	}
	if (Size == 8) 
	{
		M = new int[64];
		int _M[] = {
					 7,	13,	16,	18,	22,	22,	24,	28,
					13,	13,	18,	20,	22,	24,	28,	31,
					16,	18,	22,	22,	24,	28,	28,	32,
					18,	18,	22,	22,	24,	28,	31,	33,
					18,	22,	22,	24,	27,	29,	33,	40,
					22,	22,	24,	27,	29,	33,	40,	48,
					22,	22,	24,	28,	32,	38,	47,	57,
					22,	24,	29,	32,	38,	47,	57,	69
					};
		for (int i = 0; i < 64;i++)
		{
			M[i] = _M[i];
		}
	}
	return M;
}


int setCosineMatrix(float *Matrix, int Size)
{
	for (int i = 0; i < Size; i++)
	{
		for (int j = 0; j < Size; j++)
		{
			Matrix[i* Size + j]=
				cos( PI/(float)Size * ((float)j + 0.5)*(float)i)*sqrt(2.);
		}
	}
	for (int i = 0; i < Size; i++)
	{
			Matrix[i] = 1; 
	}
	return 1;
}

int setFourierMatrix(float *RMatrix, float *IMatrix, int Size)
{
	for(int i = 0; i< Size;i++)
	{
		for (int j = 0; j < Size; j++)
		{
			float arg = -2* PI * (float) i / Size * (float) j;
			RMatrix[Size*i+j] = cos(arg);
			IMatrix[Size*i+j] = sin(arg);
		}
	}
	return 1;
}

int setIntMatrices(int* Transform, float* Scale)
{
	Transform[0] = Transform[1] = Transform[2] = Transform[3] = 1;
	Transform[5] = Transform[8] = Transform[11] = Transform[12] = 1;
	Transform[6] = Transform[9] = Transform[10] = Transform[15] = -1;
	Transform[4] = Transform[14] = 2;
	Transform[7] = Transform[13] = -2;

	float a = 0.5f;
	float b = 0.6325f; // sqrt(2/5)
	Scale[0] = Scale[2] = Scale[8] = Scale[10] = 0.25f; // a * a
	Scale[1] = Scale[3] = Scale[4] = Scale[6] = Scale[9] = Scale[11] = Scale[12] = Scale[14] = a * b / 2;
	Scale[5] = Scale[7] = Scale[13] = Scale[15] = 0.1f; // b * b / 4 (= (2 / 5) / 4 = 1 / 10) 
	return 0;
}